//
//  AddMark.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/9/29.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "AddMark.h"
#import "AddTagCell.h"
#import "AddTagDao.h"
#import "MBTPre.h"
@interface AddMark()<UITableViewDelegate,UITableViewDataSource,AddTagCellDelegate>
{
    NSArray *image;
    NSArray *name;
    NSMutableArray *data;
    NSIndexPath *curindexPath;
}
@property (weak, nonatomic) IBOutlet UITableView *table;
- (IBAction)cancle:(id)sender;
- (IBAction)ok:(id)sender;
- (IBAction)cancleTag:(id)sender;
@property (weak, nonatomic) IBOutlet UIView *content;

@end
@implementation AddMark


+ (instancetype)headerView
{
    AddMark *footer = [[[NSBundle mainBundle] loadNibNamed:@"AddMark" owner:nil options:nil] lastObject];
    [footer initTable];
    CGRect frame = footer.frame;
    frame.size.width=SCREEN_W;
    frame.size.height=SCREEN_H;//重新设定
    footer.frame =frame;
    footer.content.layer.masksToBounds = YES;
    footer.content.layer.cornerRadius = 10;
    return footer;
    
}

-(void)initTable{
    curindexPath = [NSIndexPath indexPathForRow:0 inSection:1];
    image =@[@"-黑名单",@"骚扰电话",@"诈骗电话",@"房产中介",@"快递电话-0",@"快餐电话",@"自定义图标"];
    name =@[@"黑名单",@"骚扰电话",@"诈骗电话",@"房产中介",@"快递服务",@"快餐电话",@"自定义"];
    data =[NSMutableArray array];
    for (int i=0; i<image.count; i++) {
        AddTagDao *dao =[[AddTagDao alloc]init];
        dao.imageName=image[i];
        dao.text =name[i];
        dao.selcect =NO;
        [data addObject:dao];
    }
    _table.delegate =self;
    _table.dataSource=self;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AddTagCell *cell = [AddTagCell setAddTagCellWithTableView:tableView];
    cell.data =data[indexPath.row];
    cell.indexPath=indexPath;
    cell.delegate =self;
    return cell;
}
-(void)clickItem:(NSIndexPath *)indexPath{
    if (indexPath.row==(data.count-1)) {
        //如果点击了这里呢//设置一个回调吧
        self.closeblock();
    }else{
        if (indexPath!=curindexPath){
            AddTagDao *d = [data objectAtIndex:indexPath.row];
            d.selcect =YES;
            AddTagDao *ddd = [data objectAtIndex:curindexPath.row];
            ddd.selcect =NO;
            [_table reloadData];
            curindexPath=indexPath;
        }
    }
}
- (IBAction)cancle:(id)sender {
    //取消
    self.cancleblock();//取消标记
}

- (IBAction)ok:(id)sender {
    NSString *text =[name objectAtIndex:curindexPath.row];
    self.okTagBlock(text);
}

- (IBAction)cancleTag:(id)sender {
    //取消标
    self.cancleTagBlock();
}
@end
